import numpy


class UnivariateAnalysisRequestBody:

    def __init__(self, xfile, yfile, ppmfile, thread_path):
        # 构建PCA模型的必须元素
        self.xfile = xfile
        self.yfile = yfile
        self.ppmfile = ppmfile
        self.thread_path = thread_path
        self.dpi = 1000

        self._outliers_index = None

        # 选择要分析的变量（需要减一）
        self.chooseType = 0
        self.secondType = 1
        self.typeList = "0,1"
        self.multipletestsAlpha = 0.05
        self.multipletestsMethod = "fdr_by"

    @property
    def outliers_index(self):
        return self._outliers_index

    @outliers_index.setter
    def outliers_index(self, value):
        if value != "None":
            self._outliers_index = self.str2intList(value)

    @property
    def chooseType(self):
        return self._chooseType

    @chooseType.setter
    def chooseType(self, n):
        self._chooseType = int(n) - 1

    @property
    def secondType(self):
        return self._secondType

    @secondType.setter
    def secondType(self, n):
        self._secondType = int(n) - 1

    @property
    def typeList(self):
        return self._secondType

    @typeList.setter
    def typeList(self, n):
        self._typeList = self.str2intList(n)

    @property
    def multipletestsAlpha(self):
        return self._multipletestsAlpha

    @multipletestsAlpha.setter
    def multipletestsAlpha(self, n):
        self._multipletestsAlpha = float(n)

    def set_data(self, data):
        for key, value in data.items():  # 遍历数据字典
            if hasattr(self, key):  # 如果存在同名属性
                setattr(self, key, value)  # 则添加属性到对象中

    def str2intList(self, stringWaitToTrans):
        temp_list = stringWaitToTrans.strip(',').split(',')
        final_list = []
        for i in temp_list:
            final_list.append(int(i))
        return numpy.array(final_list)
